package com.ruoyi.cbs.project.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.cbs.project.domain.Project;
import com.ruoyi.cbs.project.domain.vo.InitSafetyBriefingRespVO;
import com.ruoyi.cbs.project.mapper.ProjectMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cbs.project.mapper.ProjectSafetyBriefingMapper;
import com.ruoyi.cbs.project.domain.ProjectSafetyBriefing;
import com.ruoyi.cbs.project.service.IProjectSafetyBriefingService;

/**
 * 项目安全交底报告Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-11-12
 */
@Service
public class ProjectSafetyBriefingServiceImpl implements IProjectSafetyBriefingService 
{
    @Autowired
    private ProjectSafetyBriefingMapper projectSafetyBriefingMapper;
    @Autowired
    private ProjectMapper projectMapper;

    /**
     * 查询项目安全交底报告
     * 
     * @param id 项目安全交底报告主键
     * @return 项目安全交底报告
     */
    @Override
    public ProjectSafetyBriefing selectProjectSafetyBriefingById(Long id)
    {
        return projectSafetyBriefingMapper.selectProjectSafetyBriefingById(id);
    }

    /**
     * 查询项目安全交底报告列表
     * 
     * @param projectSafetyBriefing 项目安全交底报告
     * @return 项目安全交底报告
     */
    @Override
    public List<ProjectSafetyBriefing> selectProjectSafetyBriefingList(ProjectSafetyBriefing projectSafetyBriefing)
    {
        return projectSafetyBriefingMapper.selectProjectSafetyBriefingList(projectSafetyBriefing);
    }

    /**
     * 新增项目安全交底报告
     * 
     * @param projectSafetyBriefing 项目安全交底报告
     * @return 结果
     */
    @Override
    public int insertProjectSafetyBriefing(ProjectSafetyBriefing projectSafetyBriefing)
    {
        projectSafetyBriefing.setCreateTime(DateUtils.getNowDate());
        return projectSafetyBriefingMapper.insertProjectSafetyBriefing(projectSafetyBriefing);
    }

    /**
     * 修改项目安全交底报告
     * 
     * @param projectSafetyBriefing 项目安全交底报告
     * @return 结果
     */
    @Override
    public int updateProjectSafetyBriefing(ProjectSafetyBriefing projectSafetyBriefing)
    {
        projectSafetyBriefing.setUpdateTime(DateUtils.getNowDate());
        return projectSafetyBriefingMapper.updateProjectSafetyBriefing(projectSafetyBriefing);
    }

    /**
     * 批量删除项目安全交底报告
     * 
     * @param ids 需要删除的项目安全交底报告主键
     * @return 结果
     */
    @Override
    public int deleteProjectSafetyBriefingByIds(Long[] ids)
    {
        return projectSafetyBriefingMapper.deleteProjectSafetyBriefingByIds(ids);
    }

    /**
     * 删除项目安全交底报告信息
     * 
     * @param id 项目安全交底报告主键
     * @return 结果
     */
    @Override
    public int deleteProjectSafetyBriefingById(Long id)
    {
        return projectSafetyBriefingMapper.deleteProjectSafetyBriefingById(id);
    }

    @Override
    public InitSafetyBriefingRespVO getInitSafeBriefingByProjectId(Long projectId) {
        //创建安全交底初始化对象
        InitSafetyBriefingRespVO respVO = new InitSafetyBriefingRespVO();
        //根据项目id获取项目信息
        Project project = projectMapper.selectProjectById(projectId);
        respVO.setSafetyNo(UUID.randomUUID().toString());
        respVO.setContractorName(project.getContractorName());
        respVO.setProjectName(project.getProjectName());
        respVO.setOwnerName(project.getProjectNo());
        respVO.setContractorLeader(project.getContractorLeader());
        respVO.setOwnerLeader(project.getOwnerLeader());
        return respVO;
    }
}
